package sk.fiit.lulco.grafy;

import java.util.Collections;

public class MinimizeColorAlgorithm extends AbstractAlgorithm {
	private static final VertexColorComparator comparator = new VertexColorComparator(HEALConstants.SortType.ASC);
	public Graph color(Graph graph) {
		Collections.sort(graph.getVertices(), comparator);
		for (Vertex vertex : graph.getVertices()) {
			int oldColor = vertex.getColor();
			int newColor = graph.getMinimalFreeColor(vertex.getNeighbours(), null);
			if (oldColor > newColor) {
				vertex.setColor(newColor);
			}
		}
		return graph;
	}
}